<template>
	<view class="content">
		<navbox title="文章列表"></navbox>
		<u-tabs :list="list1" @click="click"></u-tabs>
		<view style="margin-left: 15rpx;margin-right: 15rpx;margin-top: 10rpx;">
			<u-search shape="round" searchIconColor="#73dfff" @search="search()" v-model="title"></u-search>
		</view>
		<view class="u-page" style="margin-top: 20rpx;">
			<u-list @scrolltolower="scrolltolower">
				<u-list-item v-for="(item, index) in urls" :key="index">
					<u-cell :title="`列表长度-${index + 1}`">
						<view slot="title" class="u-slot-title" @click="turnDetail(item.id)">
							<view style="display: flex;align-items: flex-start;justify-content: flex-start;">
								<u-avatar slot="icon" shape="square" size="90" :src="item.thumbnail"
									customStyle="margin: -3px 5px -3px 0"></u-avatar>
								<view style="margin-left: 5rpx;width: 100%;">
									<view style="height: 140rpx">
										<view
											style="display: flex;align-items: center;justify-content: flex-start;margin-bottom: 10rpx;">
											<u-tag text="置顶" size="mini" v-if="item.isTop==='1'"> </u-tag>
											<view style="width: 8rpx;"></view>
											<u--text :lines="1" :text="item.title" color="#000000" size="14">
											</u--text>
										</view>
										<u--text :lines="2" :text="item.summary" color="#878787" size="13">
										</u--text>
									</view>
									<view style="display: flex;align-items: center;justify-content: space-between;">
										<u--text prefixIcon="eye" text="   157 次围观" color="#8c8c8c" size="13"></u--text>
										<u--text prefixIcon="clock" text="2022年01月23日 " color="#8c8c8c" size="13">
										</u--text>
									</view>
								</view>
							</view>
						</view>
					</u-cell>
				</u-list-item>
			</u-list>
		</view>

	</view>
</template>

<script>
	import navbox from '../components/navbox/navbox.vue'
	export default {
		data() {
			return {
				list1: [],
				urls: [],
				page: {
					pageSize: 8,
					pageNum: 1,
					title: '',
					categoryId: 0
				},
				total: '',
				title: "",
				time: ""
			}
		},
		onLoad() {
			if (this.timer) {
				clearTimeout(this.timer); // 清除定时器  
			}
			uni.showLoading({
				title: '加载中'
			});
			this.gettitle()
			this.getHotGoods()
		},
		onPullDownRefresh() {
			uni.showLoading({
				title: '加载中'
			});
			this.page.pageNum = 1
			this.getHotGoods()
			this.timer = setTimeout(() => {
				uni.stopPullDownRefresh()
			}, 1000)
		},
		methods: {
			turnDetail(id){
				uni.navigateTo({
					url:'/pagesa/airtleDetail/airtleDetail?id='+id
				})
			},
			async scrolltolower() {
				const that = this
				if (this.urls.length < this.total) {
					this.page.pageNum++
					uni.showLoading({
						title: '加载中'
					});
					uni.request({
						url: that.$baseurl + "/wexinLogin/sgArticle/listALL",
						method: 'POST',
						data: that.page,
						success(res) {
							console.log(res)
							that.urls = [...that.urls, ...res.data.data.records]
						}
					})

					setTimeout(function() {
						uni.hideLoading();
					}, 800);
				}
			},
			async gettitle() {
				const res = await this.$myRuquest({
					url: '/wexinLogin/sgCategory',
				})
				const all = {
					name: '全部',
					id: 0,
				}
				this.list1 = res.data.data
				this.list1.unshift(all)
			},
			async getHotGoods() {
				const res = await this.$myRuquest({
					url: '/wexinLogin/sgArticle/listALL',
					method: "post",
					data: this.page
				})
				console.log(res)
				this.urls = res.data.data.records
				this.total = res.data.data.total
				uni.hideLoading();
			},
			click(item) {
				this.page.pageNum = 1
				this.page.categoryId = item.id
				this.getHotGoods()
				console.log('item', item);
			},
			search() {
				this.page.title = this.title
				this.getHotGoods()
			}
		},
		components: {
			"navbox": navbox
		},
	}
</script>

<style>
	.content {
		margin-left: 10rpx;
		margin-right: 10rpx;
		margin-top: 180rpx;
	}

	.chat-custom-right {
		flex: 1;
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: column;
		justify-content: space-between;
		align-items: flex-end;
	}

	.chat-custom-text {
		font-size: 12px;
		color: #999;
	}
</style>
